{% extends "main/base.html" %}
{% load static i18n %}
{% block title %}{% trans '编辑组件' %}{% endblock %}
{% block content %}
<section class="col-lg-offset-3 col-lg-7">
    <section class="panel">
        <header class="panel-heading">
            {% trans "编辑组件" %} {% if form.errors %}<p>{% trans "您提交的数据有误,请认真检查!" %}{{ form.errors }}</p>{% endif %}{{ form.non_field_errors }}
        </header>
        {% if object.equipment_assembly.created_by_id == request.user.pk or request.user.pk in object.equipment_assembly.cooperators or request.user.is_staff %}
        <div class="panel-body">
            <form method="post" class="form-horizontal">{% csrf_token %}
                <div class="form-group">
                    <div class="col-lg-2">{{ form.equipment.label_tag }}</div>
                    <div class="col-lg-10">
                        <div class="input-group">
                            <input class="form-control" type="text" id="equipment_search" value="" placeholder="搜索设备" onchange="refreshBtn();">
                            <span class="input-group-btn"><label class="btn btn-primary" id="search_btn" onclick="loadXMLDoc();">搜索</label></span>
                        </div>
                    </div>
                    <div class="col-lg-offset-2 col-lg-10">
                        <select name="equipment" class="selectpicker form-control" data-live-search="true" required id="id_equipment">
                            <option value="{{ object.equipment.pk }}" selected>{{ object.equipment }}</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-2">{{ form.amount.label_tag }}</div>
                    <div class="col-lg-4">{{ form.amount }} {{ form.amount.errors }}</div>
                    <div class="col-lg-2">{{ form.order_index.label_tag }}</div>
                    <div class="col-lg-4">{{ form.order_index }} {{ form.order_index.errors }}</div>
                </div>
                <div class="form-group">
                    <div class="col-lg-2">{{ form.notes.label_tag }}</div>
                    <div class="col-lg-10">{{ form.notes }}{{ form.notes.errors }}</div>
                </div>
                <div class="form-group">
                    <div class="col-lg-offset-2 col-lg-4" align="left">
                        <a href="{% url 'main:assembly_item_delete' object.pk %}"><label class="btn btn-danger">{% trans "删除" %}</label></a>
                    </div>
                    <div class="col-lg-6" align="right">
                        <button type="submit"  class="btn btn-primary">{% trans "提交" %}</button>
                    </div>
                </div>
            </form>
        </div>
        {% endif %}
    </section>
</section>
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'main/js/load_equipment.js' %}"></script>
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-switch.js' %}"></script>
{% endblock %}